PreviousTracker indexSee it online !

(308/308) 1910 - JavaMacros plugin

Said plugin's document is very poor. They said the Java doc will contains more information about how to write macro using Java and compiled to class bytecode and run this .class as JEdit macro. But the Jar file JavaMacros.jar contains no Java doc at all. I have no idea how to use it and it seemed the plugin is no longer updated. Please consider updating it or just remove it and clearly state that bytecode .class file currently can't be run as JEdit macro and you can't write JEdit macro in Java so other people know that it is currently impossible and they would have a look to implement an actual working solution. Thanks.

Submitted ruanjiaxing - 2020-05-24 14:30:12.745000 Assigned daleanson
Priority 5 Labels
Status open Group
Resolution None

Comments

2020-05-24 19:41:07.202000
daleanson

Well, you're right, the documentation is poor. However, the plugin does work as advertised, but it's a little unusual. Here's a working example, more or less from the JavaMacro code itself, which would have been in the javadoc if the javadoc had actually been included with the plugin:

~~~
package macros;


import javamacros.*;

import org.gjt.sp.jedit.*;
import org.gjt.sp.jedit.textarea.JEditTextArea;


public class Hello_World implements MacroClass {

public void run( Buffer buffer, View view, Macros.Macro macro, JEditTextArea textArea ) throws Exception {
Macros.message( view, "Hello World!" );
}
}
~~~

Put this in a directory named "macros". Compile it like this:

~~~
javac -cp /path/to/JavaMacros.jar:/path/to/jedit.jar:. macros/Hello_World.java
~~~

Copy the resulting .class file to your jEdit settings directory/macros.

Now the unusual part, the JavaMacros.jar file needs to be added to the classpath that you use to start jEdit. I start jEdit from a shell script, so my start up line looks like this:

~~~
java -Xmx620m -Xms512m ${ANTIALIAS_ALL} "-Djedit.home=$JEDIT_HOME" -cp ~/.jedit/jars/JavaMacros.jar -jar "$JEDIT_HOME/jedit.jar" -reuseview "$@"
~~~

So restart jEdit with the JavaMacros.jar in the classpath, and you should see "Hello World" in the Macros menu, and clicking it show a message box saying "Hello World".

The plugin code does need some updating, the build file doesn't work out of the box anymore and as you mentioned, the documentation is poor and the javadoc is missing altogether. I'll see if I can find time to fix those issues. I'd like to see if there is a way so that the JavaMacros.jar doesn't have to be included in jEdit's start up classpath for the macros to work, that's a significant barrier to user adoption of this plugin.

2020-05-24 19:41:34.540000
daleanson

- **assigned_to**: Dale Anson
- **Group**: -->

2020-05-25 16:08:18.399000
ruanjiaxing

Thank you. Your example worked. Could you extend the plugin so it would run a jar file and not just a .class file? I found .class file is a bit inconvenient. I also don't understand why the author didn't start with jar file from the beginning but chose .class file instead.

2020-05-25 18:30:44.458000
daleanson

Probably not. The idea of a macro is something small, quick, and not very complicated. If you need more than that, as in multiple classes in a jar file, then you probably need a plugin, which is packaged in a jar file.

2020-05-26 05:29:18.579000
ruanjiaxing

Thanks. I got it.